<template>
  <div v-loading="loading">
    <iFrame v-model:src="url" />
  </div>
</template>

<script setup name="ReportManager">
import { onBeforeRouteLeave } from 'vue-router'
//import { initCustomOpation } from '../index.js'
const { proxy } = getCurrentInstance()
const store = useStore()
const ureportURL = import.meta.env.VITE_APP_UREPORT_URL
const ureportStore = store.state.template.ureportUrl
const url = ref(ureportStore)
let loading = ref(false)

/* onMounted(() => {
  setUrl()
  window.addEventListener('message', function (e) {
    console.log(e)
    console.log(1111111)
    localStorage.setItem('ureportDesigner', e.data.data)
    url.value = ureportURL + localDesigner
  })
})
onActivated(() => {
  setUrl()
}) */
watch(
  () => proxy.$route,
  (val) => {
    if (val) {
      setUrl()
    }
  },
  {
    immediate: true,
  }
)
function setUrl() {
  const localDesigner = localStorage.getItem('ureportDesigner')
  if (localDesigner) {
    proxy.$store.commit('SET_UREPORT_URL', localDesigner)
    url.value = ureportURL + localDesigner
    //initCustomOpation()
  }
  //proxy.$fn.initLayout(proxy, { loading })
}
/* const isCloseDesign = computed(() => {
  return proxy.$store.state.tabsView.isCloseDesign
})
onBeforeRouteLeave((to, from, next) => {
  if (isCloseDesign.value) {
    next()
    return
  }
  proxy
    .$confirm('有未保存的修改,系统可能不会保存您所做的更改,是否继续?', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    })
    .then(() => {
      proxy.$store.dispatch('tabsView/updateIsCloseDesign', false)
      next()
    })
    .catch(() => {
      proxy.$store.dispatch('tabsView/updateIsCloseDesign', false)
    })
}) */
</script>
